home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-desktop-9.10-i386-PL.iso / casper / filesystem.squashfs / tmp / customization-scripts / customize < prev    next >
Text File  |  2009-02-04  |  6KB  |  175 lines

  1. #!/bin/bash
  2.  
  3. ###################################################################################
  4. # UCK - Ubuntu Customization Kit                                                  #
  5. # Copyright (C) 2006-2009 UCK Team                                                #
  6. #                                                                                 #
  7. # UCK is free software: you can redistribute it and/or modify                     #
  8. # it under the terms of the GNU General Public License as published by            #
  9. # the Free Software Foundation, either version 3 of the License, or               #
  10. # (at your option) any later version.                                             #
  11. #                                                                                 #
  12. # UCK is distributed in the hope that it will be useful,                          #
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of                  #
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                   #
  15. # GNU General Public License for more details.                                    #
  16. #                                                                                 #
  17. # You should have received a copy of the GNU General Public License               #
  18. # along with UCK.  If not, see <http://www.gnu.org/licenses/>.                    #
  19. ###################################################################################
  20.  
  21. function failure()
  22. {
  23.     echo "$@"
  24.     exit 1
  25. }
  26.  
  27. function prepare_install()
  28. {
  29.     #try 2 times to avoid slow proxies failures
  30.     apt-get update || apt-get update || failure "apt-get update failed, error=$?"
  31. }
  32.  
  33. function install_packages()
  34. {
  35.     apt-get install --assume-yes --force-yes "$@" || failure "apt-get install $@ failed, error=$?"
  36. }
  37.  
  38. function remove_packages()
  39. {
  40.     apt-get --purge remove --assume-yes --force-yes "$@" || failure "apt-get remove $@ failed, error=$?"
  41. }
  42.  
  43. function run_package_manager()
  44. {
  45.     echo "Starting package application..."
  46.     
  47.     PACKAGE_APP=`which adept`
  48.     PACKAGE_APP_OPTIONS=(--caption "UCK Package Manager")
  49.     if [ "$PACKAGE_APP" = "" ]; then
  50.         PACKAGE_APP=`which adept_manager`
  51.     fi
  52.     if [ "$PACKAGE_APP" = "" ]; then
  53.         PACKAGE_APP=`which synaptic`
  54.         PACKAGE_APP_OPTIONS=(-t "UCK Package manager")
  55.     fi
  56.     
  57.     if [ "$PACKAGE_APP" = "" ]; then
  58.         dialog_msgbox "Failure" "Unable to find any package manager application"
  59.     else
  60.         $PACKAGE_APP "${PACKAGE_APP_OPTIONS[@]}"
  61.         RESULT=$?
  62.     
  63.         if [ $RESULT -ne 0 ]; then
  64.             dialog_msgbox "Failure" "Running package application $PACKAGE_APP failed, error=$RESULT"
  65.         fi
  66.     fi
  67. }
  68.  
  69. function run_console()
  70. {
  71.     echo "Starting console application..."
  72.     
  73.     CONSOLE_APP=`which konsole`
  74.     CONSOLE_APP_OPTIONS=(--caption "UCK customization console" -e /bin/bash)
  75.     if [ "$CONSOLE_APP" = "" ]; then
  76.         CONSOLE_APP=`which gnome-terminal`
  77.         CONSOLE_APP_OPTIONS=(-t "UCK customization console" -e /bin/bash)
  78.     fi
  79.     if [ "$CONSOLE_APP" = "" ]; then
  80.         CONSOLE_APP=`which xfce4-terminal`
  81.         CONSOLE_APP_OPTIONS=(-t "UCK customization console" -e /bin/bash)
  82.     fi
  83.     if [ "$CONSOLE_APP" = "" ]; then
  84.         CONSOLE_APP=`which xterm`
  85.         CONSOLE_APP_OPTIONS=(-title "UCK customization console" -e /bin/bash)
  86.     fi
  87.     
  88.     if [ "$CONSOLE_APP" = "" ]; then
  89.         dialog_msgbox "Failure" "Unable to find any console application"
  90.     else
  91.         $CONSOLE_APP "${CONSOLE_APP_OPTIONS[@]}"
  92.         RESULT=$?
  93.     
  94.         if [ $RESULT -ne 0 ]; then
  95.             dialog_msgbox "Failure" "Running console application $CONSOLE_APP failed, error=$RESULT"
  96.         fi
  97.     fi
  98. }
  99.  
  100. SCRIPT_DIR=`dirname "$0"`
  101. . "$SCRIPT_DIR/gui.sh"
  102.  
  103. LIVECD_LANGS=`cat "$SCRIPT_DIR/language_packs"`
  104. RUN_MANUAL_CUSTOMIZATIONS=`cat "$SCRIPT_DIR/run_manual_customizations"`
  105. DESKTOP_TYPE=`cat "$SCRIPT_DIR/desktop_type"`
  106.  
  107. if [ -z "$LIVECD_LANGS" ]; then
  108.     failure "Live CD language not set, please put language packs codes (for example: en, pl, fr) into $SCRIPT_DIR/language_packs"
  109. fi
  110.  
  111. DESKTOP_FLAVOURS=`cat "$SCRIPT_DIR/desktop_types"`
  112.  
  113. prepare_install || failure "Preparing installation failed, error=$?"
  114.  
  115. echo "Installing language packs ($LIVECD_LANGS)..."
  116.  
  117. PACKAGES_TO_INSTALL=""
  118. LANGPACKS_CONCATENATED=""
  119.  
  120. for LANGPACK in $LIVECD_LANGS; do
  121.     PACKAGES_TO_INSTALL="$PACKAGES_TO_INSTALL language-pack-$LANGPACK language-support-$LANGPACK"
  122.  
  123.     if [ "$DESKTOP_FLAVOURS" ]; then
  124.         for FLAVOUR in $DESKTOP_FLAVOURS; do
  125.             if [ $FLAVOUR == "gnome" ] || [ $FLAVOUR == "kde" ]; then
  126.                 PACKAGES_TO_INSTALL="$PACKAGES_TO_INSTALL language-pack-$FLAVOUR-$LANGPACK"
  127.             fi
  128.         done
  129.     fi
  130.  
  131.     if [ -z "$LANGPACKS_CONCATENATED" ]; then
  132.         LANGPACKS_CONCATENATED="$LANGPACK"
  133.     else
  134.         LANGPACKS_CONCATENATED="$LANGPACKS_CONCATENATED|$LANGPACK"
  135.     fi
  136. done
  137.  
  138. install_packages $PACKAGES_TO_INSTALL || failure "Installing language packs failed, error=$?"
  139.  
  140. #NOTE: we first install language pack, then remove others as installing language pack might pull packages
  141. #which were not previously present
  142. echo "Removing unnecessary language packages..."
  143. REMOVED_PACKAGES=`dpkg-query --show | cut -f1 | grep -E '^(language-pack|language-support)' | grep -v -E "[-]($LANGPACKS_CONCATENATED)\>"`
  144. remove_packages $REMOVED_PACKAGES || failure "Removing packages failed, error=$?"
  145.  
  146. if [ "$RUN_MANUAL_CUSTOMIZATIONS" = "yes" ] ; then
  147.     #Create DBUS uuid so that KDE4 apps work.
  148.     echo "Creating DBUS uuid"
  149.     dbus-uuidgen --ensure
  150.     while true ; do
  151.         CHOICE_PACKAGE_MANAGER="Run package manager"
  152.         CHOICE_CONSOLE="Run console application"
  153.         CHOICE_EXIT="Continue building"
  154.         CHOICE=`dialog_menu "Please choose customization action" "$CHOICE_PACKAGE_MANAGER" "$CHOICE_CONSOLE" "$CHOICE_EXIT"`
  155.         RESULT=$?
  156.  
  157.         if [ $RESULT -ne 0 ] ; then
  158.             failure "Script cancelled by user"
  159.         fi
  160.         #workaround for KDE bug (https://bugs.kde.org/show_bug.cgi?id=139025)
  161.         CHOICE=`echo "$CHOICE" | grep -v -i kwrited | tail -n1`
  162.  
  163.         echo "CHOICE='$CHOICE'"
  164.  
  165.         if [ "$CHOICE" = "$CHOICE_EXIT" ] ; then
  166.             break
  167.         elif [ "$CHOICE" = "$CHOICE_PACKAGE_MANAGER" ] ; then
  168.             run_package_manager
  169.         elif [ "$CHOICE" = "$CHOICE_CONSOLE" ] ; then
  170.             run_console
  171.         fi
  172.     done
  173. fi
  174.  
  175. echo "Done"